const express = require('express');
const ejs = require("ejs");
const logger = require("morgan");
const bodyParser = require("body-parser");
const path = require("path");
const routerConfig = require("./route-config");

const app = express();
app.engine('html', ejs.renderFile);
app.set('view engine', 'html');
app.set('views', path.join(__dirname, 'views'));
app.use(express.static(__dirname + '/public'));
app.use(logger());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));

//加载路由配置
for (let i = 0; i < routerConfig.routers.length; i++) {
    const router = routerConfig.routers[i];
    app.use(router.path, require(router.file));
    console.log(`加载路由配置:${router.path}`);
}

app.listen(80, () => {
    console.log(`Server started on 80`);
});